//
//  LPQuestionnaireViewController.m
//  muce
//
//  Created by  yunshao on 2018/2/27.
//  Copyright © 2018年  yunshao. All rights reserved.
//

/** 问卷调查 */

#import "LPQuestionnaireViewController.h"
#import "pch.h"
#import "AppDelegate.h"
#import "LPQuestionnaireView.h"
#import <IQKeyboardManager/IQKeyboardManager.h>

@interface LPQuestionnaireViewController ()
@property(nonatomic,strong)UIView * backView;
@property(nonatomic,strong)UIButton * backButton;               //返回按钮
@property(nonatomic,strong)UILabel * titleLable;                //标题
//@property (nonatomic,strong)NSArray * dataArray;                //回传数据

@end

@implementation LPQuestionnaireViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self addMianView];
}

-(void)addMianView {
    
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DSDevice_W, DSFixedPX(110))];
    _backView.backgroundColor = DSColorWithHex(0x3279ca);
    _backView.userInteractionEnabled = YES;
    [self.view addSubview:_backView];
    
//    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    _backButton.frame = CGRectMake(DSFixedPX(20), DSFixedPX(40), DSFixedPX(50), DSFixedPX(50));
//    _backButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
//    [_backButton setImage:[UIImage imageNamed:@"title_back"] forState:UIControlStateNormal];
//    [_backButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
//    [_backView addSubview:_backButton];
    _titleLable = [[UILabel alloc]initWithFrame:CGRectMake(DSFixedPX(40), DSFixedPX(40), DSDevice_W - DSFixedPX(80), DSFixedPX(50))];
    _titleLable.text = @"问卷调查";
    _titleLable.textAlignment = NSTextAlignmentCenter;
    _titleLable.font = DSFontSize(16);
    _titleLable.textColor = DSColorWithHex(0xffffff);
    [_backView addSubview:_titleLable];
    
    @weakify_self;
    // 初始化问卷视图
    LPQuestionnaireView *questionnaireView = [[LPQuestionnaireView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_backView.frame), DSDevice_W, DSDevice_H - CGRectGetMaxY(_backView.frame)) dictioanry:self.questionaireDic];
    [self.view addSubview:questionnaireView];
    questionnaireView.submitBlock = ^(NSArray *array) {
        @strongify_self;
        if (array.count > 0) {
            // 提交问卷  如果有数据，就执行网络请求，提交数据，否则就直接返回就行了。
            [LPRequestParser posthttpSaveQuestionnaireJsonAnswer:array block:^(id responseObject, NSError *error) {
                if (responseObject) {
                    NSLog(@"上传成功??");
                }
            }];
        }else{
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    };
}


#pragma mark--init**********************************初始化*******************************
-(instancetype)init{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(topicIsFished:) name:@"topicIsFished" object:nil];
    }
    return self;
}
#pragma mark *********************移除通知 *************************
/**
 拿到测评结果，发出的通知。 将记录播放时长的timeCount 置空为0
 */
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"topicIsFished" object:nil];
}
-(void)topicIsFished:(NSNotification *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
}


//-(void)backButtonClicked{
//
//
//    if (_dataArray.count > 0) {
//        [self dismissViewControllerAnimated:YES completion:nil];
//    }else{
//        [SVProgressHUD showErrorWithStatus:@"请先完善问卷调查"];
//    }
//
//    /*   分开判断的哟
//    if ([[LPCommonTool readIdengit] integerValue] == 2) {
//
//    }else if ([[LPCommonTool readIdengit] integerValue] == 1){
//        [self dismissViewControllerAnimated:YES completion:nil];
//    }
//     */
//}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
